<template>
  <div class="home">
    <h1>这是华丽的home页面</h1>
      <div>位置城市：{{autolocation}}</div>
      <router-link to="/about">去About页面</router-link>
  </div>
</template>

<script>
	import AMap from 'AMap' // 引入高德地图
	export default {
		data() {
			return {
				autolocation: '北京'
			}
		},
		mounted() {
      this.getLocation();
      localStorage.weizhi=this.autolocation
      window.console.log(localStorage.weizhi)
		},
		methods: {
			// 获取定位
			getLocation() {
				const _this = this;
				AMap.plugin('AMap.CitySearch', function() {
					var citySearch = new AMap.CitySearch()
          window.console.log(citySearch);
					citySearch.getLocalCity(function(status, result) {
						if (status === 'complete' && result.info === 'OK') {
							// 查询成功，result即为当前所在城市信息
							window.console.log('通过ip获取当前城市：', result.city);
							_this.autolocation = result.city;
						}else{
              alert("定位失败")
            }
          })
				});
			}
		}
	}
</script>
